<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>支付</title>
<!-- Bootstrap core CSS -->
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<!-- 时间控件样式 -->
<link
	href="/admin/css/plugins/datetimepicker/bootstrap-datetimepicker.min.css"
	rel="stylesheet" media="screen" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" />
<link href="/admin/public/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/templet_form.css" />
<script src="/phone/js/md5.js" type="text/javascript"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<style>
th.prev {
	background: url(../img/dateleft.png) -3px !important;
}

th.next {
	background: url(../img/dateright.png) -10px !important;
}

table a {
	color: #fff !important;
}
</style>
</head>
  <body>  
        <div class="index_box" style="display: none;">  
            <div class="apply_name">微信js支付测试</div>  
            <div class="branch_con">  
                <ul>  
                    <li><span class="name">测试支付信息</span></li>  
                </ul>  
                <p class="cz_btn"><input type="button" value="立即支付" onclick="pay();"></p>  
            </div>  
        </div>  
      	
      		<script src="/admin/public/jquery-1.11.3.js"></script>
        
        <script>
         var appId = "";
        var timeStamp ="";
        var nonceStr = "";
        var paySign = "";
        var pkg = "";
        var signType = "MD5";
        var orderNo="";
        var logId="";
        //var userId=$.cookie("userId");
       // var money=$.cookie("money");
        
        
        function getQueryString(name) { 
        	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
        	var r = window.location.search.substr(1).match(reg); 
        	if (r != null) return unescape(r[2]); return null; 
        }
        if(getQueryString("type")=='cz'){
        	var userId=getQueryString("userId");
            var czMoney=getQueryString("czMoney");
            var zsMoney=getQueryString("zsMoney");
            var sign=getQueryString("sign");
        }else if(getQueryString("type")=='ka'){
        	var imgId=getQueryString("imgId");
        	var cardId=getQueryString("cardId");
        	var timer=getQueryString("timer");
        	var qian=getQueryString("qian");
        	var period=getQueryString("period");
        	var yue=getQueryString("yue");
        	var shopId=getQueryString("shopId");
        	var couponId=getQueryString("couponId");
            var sign=getQueryString("sign");
        }else if(getQueryString("type")=='mk'){
        	var coursesId=getQueryString("coursesId");
        	var ptj=getQueryString("ptj");
        	var shopId=getQueryString("shopId");
        	var coursesType=getQueryString("coursesType");
        	var coursesInfoId=getQueryString("coursesInfoId");
        	var kid=getQueryString("kid");
        	var couponId=getQueryString("couponId");
            var sign=getQueryString("sign");
        	//var dk=getQueryString("dk");
        }else if(getQueryString("type")=='xlypd'){
        	var ptj=getQueryString("ptj");
        	var shopId=getQueryString("shopId");
        	var coursesType=getQueryString("coursesType");
        	var coursesInfoId=getQueryString("coursesInfoId");
        	var couponId=getQueryString("couponId");
            var sign=getQueryString("sign");
        }else if(getQueryString("type")=='tkpd'){
        	var coursesId=getQueryString("coursesId");
        	var ptj=getQueryString("ptj");
        	var shopId=getQueryString("shopId");
        	var coursesType=getQueryString("coursesType");
        	var coursesInfoId=getQueryString("coursesInfoId");
        	var kid=getQueryString("kid");
        	var couponId=getQueryString("couponId");
            var sign=getQueryString("sign");
        }	
        
        
        
        
        $(function () {
        if(getQueryString("type")=='cz'){
        	var sign1 = MD5("czMoney"+czMoney+"zsMoney"+zsMoney+"asd");
        	if(sign1!=sign){
        		alert("验签失败！");
        		return false;
        	}
        	 $.ajax({
 				type:"post",
 				data:{"money":czMoney,"body":"充值","zsMoney":zsMoney,"qf":"1"},
 				url:"/couponsConfirm",
 				success:function(data){
 					appId = data.appid;
 					timeStamp = data.timestamp;
 					nonceStr = data.nonceStr;
 					pkg = data.packageValue;
 					paySign = data.paySign;
 					orderNo=data.orderNo;
 					pay();
 				},
 				error:function(data){
 					
 				}
 			})
        }else if(getQueryString("type")=='ka'){
        	var sign1 = MD5("qian"+qian+"asd");
        	if(sign1!=sign){
        		alert("验签失败！");
        		return false;
        	}
        	$.ajax({
 				type:"post",
 				data:{"money":qian,"body":"购买卡片","qf":"2","couponId":couponId},
 				url:"/couponsConfirm",
 				success:function(data){
 					appId = data.appid;
 					timeStamp = data.timestamp;
 					nonceStr = data.nonceStr;
 					pkg = data.packageValue;
 					paySign = data.paySign;
 					orderNo=data.orderNo;
 					logId=data.logId;
 					pay();
 				},
 				error:function(data){
 					
 				}
 			})
        }else if(getQueryString("type")=='mk'){
        	var sign1 = MD5("ptj"+ptj+"asd");
        	if(sign1!=sign){
        		alert("验签失败！");
        		return false;
        	}
        	$.ajax({
 				type:"post",
 				data:{"money":ptj,"body":"购买课程","qf":"2","couponId":couponId},
 				url:"/couponsConfirm",
 				success:function(data){
 					appId = data.appid;
 					timeStamp = data.timestamp;
 					nonceStr = data.nonceStr;
 					pkg = data.packageValue;
 					paySign = data.paySign;
 					orderNo=data.orderNo;
 					logId=data.logId;
 					pay();
 				},
 				error:function(data){
 					
 				}
 			})
        }else if(getQueryString("type")=='xlypd'){
        	var sign1 = MD5("ptj"+ptj+"asd");
        	if(sign1!=sign){
        		alert("验签失败！");
        		return false;
        	}
        	$.ajax({
 				type:"post",
 				data:{"money":ptj,"body":"训练营排队购买课程","qf":"2","couponId":couponId},
 				url:"/couponsConfirm",
 				success:function(data){
 					appId = data.appid;
 					timeStamp = data.timestamp;
 					nonceStr = data.nonceStr;
 					pkg = data.packageValue;
 					paySign = data.paySign;
 					orderNo=data.orderNo;
 					logId=data.logId;
 					pay();
 				},
 				error:function(data){
 					
 				}
 			})
        }else if(getQueryString("type")=='tkpd'){
        	var sign1 = MD5("ptj"+ptj+"asd");
        	if(sign1!=sign){
        		alert("验签失败！");
        		return false;
        	}
        	$.ajax({
 				type:"post",
 				data:{"money":ptj,"body":"排队购买课程","qf":"2","couponId":couponId},
 				url:"/couponsConfirm",
 				success:function(data){
 					appId = data.appid;
 					timeStamp = data.timestamp;
 					nonceStr = data.nonceStr;
 					pkg = data.packageValue;
 					paySign = data.paySign;
 					orderNo=data.orderNo;
 					logId=data.logId;
 					pay();
 				},
 				error:function(data){
 					
 				}
 			})
        }	
        

    	});
         
         function onBridgeReady(){
        	   WeixinJSBridge.invoke(
        	       'getBrandWCPayRequest', {
        	           "appId":appId,     //公众号名称，由商户传入     
        	           "timeStamp":timeStamp,         //时间戳，自1970年以来的秒数     
        	           "nonceStr":nonceStr, //随机串     
        	           "package":pkg,     
        	           "signType":"MD5",         //微信签名方式：     
        	           "paySign":paySign//微信签名 
        	       },
        	       function(res){
        	           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
        	        	   if(getQueryString("type")=='cz'){
        	        		 //支付成功发送ajax请求修改资金表和资金记录表
            	        	  /*  $.ajax({
    						       data:{"userId":userId,"money":czMoney,"zsMoney":zsMoney,"orderNo":orderNo},
    						       url:"/phone/recharge",
    						       type:"get",
    						       dataType:"json",
    						       success:function(data){
    						    	   alert(data.msg);
    						    	   if(data.result){
    						    		   window.location.href = "/phone/login";
    						    	   }else{
    						    		   window.location.href = "/phone/yue?id="+userId;
    						    	   }
    						       },
    						       error:function(data){
    						    	   alert("系统异常！");
    						       }
    						    }); */
    						    alert("充值成功！");
    						    window.location.href = "/phone/login";
        	        	   }else if(getQueryString("type")=='ka'){
        	        			  $.ajax({
        	        			        type:"get",
        	        			        url:"/phone/buyCard",
        	        			        data:{"cid":cardId,"t":timer,"jg":qian,"num":period,"imgId":imgId,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
        	        			        datatype:"json",
        	        			        success:function(data){
        	        			        	alert(data.msg);
        	        			        	if(data.cardTypeId==1){
        	        			        		window.location.href="/phone/GroupChat?sid="+shopId;
        	        			        	}else{
        	        			        		window.location.href="/phone/Discount";
        	        			        	}
        	        			        },
        	        			        error:function(data){
        	        			        	alert("系统异常！");
        	        			        }
        	        			    });
        	        		   
        	        			    
        	        	   }else if(getQueryString("type")=='mk'){
	        	              var shopId=getQueryString("shopId");
	        	               	var coursesInfoId=getQueryString("coursesInfoId");
	        	               	var coursesId=getQueryString("coursesId");
	        	               	var kid=getQueryString("kid");
        	        			 if(coursesType==2){
        	        				 //购买训练营
        	        				 $.ajax({
        	        				        type:"get",
        	        				        url:"/phone/Gmxly",
        	        				        data:{"cid":coursesInfoId,"m":ptj,"shopId":shopId,"t":coursesType,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
        	        				        datatype:"json",
        	        				        success:function(data){
        	        				        	if(data.success==true){
        	        				        		alert(data.msg);
        	        				        		window.location.href="/phone/GroupChat?sid="+shopId+"&t="+coursesType;
        	        				        	}else{
        	        				        		alert(data.msg);
        	        				        		window.location.href="/phone/selKC?shopId="+shopId+"&t="+coursesType;
        	        				        	}
        	        				        },
        	        				        error:function(data){
        	        				        	alert("系统异常！");
        	        				        }
        	        				    });
        	        			 }else{
        	        				 //购买团课
        	        				 $.ajax({
        	        				        type:"get",
        	        				        url:"/phone/Yuyue",
        	        				        data:{"cid":coursesId,"m":ptj,"shopId":shopId,"t":coursesType,"kid":kid,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
        	        				        datatype:"json",
        	        				        success:function(data){
        	        				        	if(data.success==true){
        	        				        		alert(data.msg);
        	        				        		window.location.href="/phone/GroupChat?sid="+shopId+"&t="+coursesType;
        	        				        	}else{
        	        				        		alert(data.msg);
        	        				        		window.location.href="/phone/selKC?shopId="+shopId+"&t="+coursesType;
        	        				        	}
        	        				            
        	        				        },
        	        				        error:function(data){
        	        				        	alert("系统异常！");
        	        				        }
        	        				    });
        	        			 }
        	        	   }else if(getQueryString("type")=='xlypd'){
        	        			  var coursesInfoId=getQueryString("coursesInfoId");
        	        			 var m=getQueryString("ptj");
        	        			 var shopId=getQueryString("shopId");
        	        			 var t=getQueryString("coursesType");
        	        		   $.ajax({
        	        		        type:"get",
        	        		        url:"/phone/xlyPaidui",
        	        		        data:{"cid":coursesInfoId,"money":ptj,"sid":shopId,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
        	        		        datatype:"json",
        	        		        success:function(data){
        	        		        	if(data.success==true){
        	        		        		alert(data.msg);
        	        		        		window.location.href="/phone/GroupChat?sid="+shopId+"&t="+t;
        	        		        	}else{
        	        		        		alert(data.msg);
        	        		        		window.location.href="/phone/CAMP";
        	        		        	}
        	        		        },
        	        		        error:function(data){
        	        		        	alert("系统异常！");
        	        		        }
        	        		    }); 
        	        	   }else if(getQueryString("type")=='tkpd'){
        	        		 var cid=getQueryString("coursesId");
      	        			 var coursesInfoId=getQueryString("coursesInfoId");
      	        			 var m=getQueryString("ptj");
      	        			 var shopId=getQueryString("shopId");
      	        			 var t=getQueryString("coursesType");
       	        		   	 if(t==2){
       	        				 //购买训练营
       	        				 $.ajax({
       	        				        type:"get",
       	        				        url:"/phone/Gmxly",
       	        				        data:{"cid":coursesInfoId,"m":m,"shopId":shopId,"t":t,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
       	        				        datatype:"json",
       	        				        success:function(data){
       	        				        	if(data.success==true){
       	        				        		alert(data.msg);
       	        				        		window.location.href="/phone/GroupChat?sid="+shopId+"&t="+t;
       	        				        	}else{
       	        				        		alert(data.msg);
       	        				        		window.location.href="/phone/CAMP";
       	        				        	}
       	        				        },
       	        				        error:function(data){
       	        				        	alert("系统异常！");
       	        				        }
       	        				    });
       	        			 }else{
       	        				 //购买团课
       	        				 $.ajax({
       	        				        type:"get",
       	        				        url:"/phone/pdYuyue",
       	        				        data:{"cid":cid,"m":m,"shopId":shopId,"t":t,"kid":kid,"orderNo":orderNo,"logId":logId,"couponId":couponId,"zf":1},
       	        				        datatype:"json",
       	        				        success:function(data){
       	        				        	if(data.success==true){
       	        				        		alert(data.msg);
       	        				        		window.location.href="/phone/GroupChat?sid="+shopId+"&t="+t;
       	        				        	}else{
       	        				        		alert(data.msg);
       	        				        		window.location.href="/phone/selKC?shopId="+shopId+"&t="+t;
       	        				        	}
       	        				        },
       	        				        error:function(data){
       	        				        	alert("系统异常！");
       	        				        }
       	        				    });
       	        			 }
        	        	   }
        	        	   
        	        	  
        	        	   
        	        	   
        	           }else if(res.err_msg == "get_brand_wcpay_request:cancel" ){
        	        	   window.location.href="/phone/bdtel";
        	           }else{
        	        	   alert("支付失败"+res.err_msg);
        	           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok 
        	       }
        	   ); 
        	}
         function pay(){
        	 if (typeof WeixinJSBridge == "undefined"){
        		   if( document.addEventListener ){
        		       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        		   }else if (document.attachEvent){
        		       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
        		       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        		   }
        		}else{
        		   onBridgeReady();
        		} 
         }
        	         
        </script>  
    </body> 
</html>
